`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company: 
// Dependencies: 
// Engineer: 
// 
// Create Date:    22:41:36 04/18/2014 
// Design Name: 
// Module Name:    icon 
// Project Name: 
// Target Devices: 
// Tool versions: 
// Description: 
//
//
// Revision: 
// Revision 0.01 - File Created
// Additional Comments: 
//
//////////////////////////////////////////////////////////////////////////////////
module icon(
	input	[10:0]		pixel_row,
	input	[10:0]		pixel_column,
	input	[7:0] 	LocX_reg,			// X-coordinate of rojobot's location		
	input	[7:0]		LocY_reg,			// Y-coordinate of rojobot's location
	input	[7:0]		BotInfo_reg,	
	input	[1:0] 	ROM_data,
	
	output [10:0] 	ROM_addr,
	output reg [1:0]	icon
    );
	 
	wire signed [10:0] x_coord;
	wire signed [10:0] y_coord;

	assign x_coord		=	(pixel_column	-	{LocX_reg, 1'b0, 1'b0}	+ 14);		//adding offset
	assign y_coord		=	(pixel_row		-	{LocY_reg, 1'b0, 1'b0}	+ 14);
	assign ROM_addr	=	{BotInfo_reg[2:0], y_coord[4:1], x_coord[4:1]};
	

/*	 
	assign x_coord		=	(pixel_column	>	{LocX_reg, 1'b0, 1'b0})	? (pixel_column	-	{LocX_reg, 1'b0, 1'b0})	:	({LocX_reg, 1'b0, 1'b0}	-	pixel_column);
	assign y_coord		=	(pixel_row	   >	{LocY_reg, 1'b0, 1'b0})	? (pixel_row		-	{LocY_reg, 1'b0, 1'b0})	:	({LocY_reg, 1'b0, 1'b0}	-	pixel_row);
	assign ROM_addr	=	{x_coord[3:0], y_coord[3:0]};
*/
/*
	always @(*)
	begin 
	 if((((pixel_column[8:2] > (LocX_reg - 2'b11)) && (pixel_column[8:2] < (LocX_reg + 2'b11)))	&&		((pixel_row[8:2] > (LocY_reg - 2'b10))	&&	(pixel_row[8:2] < (LocY_reg + 2'b11)))) || ((pixel_column[8:2] == LocX_reg) && (pixel_row[8:2] == LocY_reg)))
	 begin
		icon[1:0] = ROM_data;					
	 end
	 else		
	 begin
		icon = 2'b00;			//else transparent
	 end
	end		
*/

	always @(*)
	begin 
	 if(x_coord >= 0 && x_coord <= 31 && y_coord >= 0 && y_coord <= 31)
	 begin
		icon[1:0] = ROM_data;					
	 end
	 else		
	 begin
		icon = 2'b00;			//else transparent
	 end
	end			

			
endmodule
